<?php

/**
 * @author          Le Van Chien
 * @skype           ps.chienlv
 * @yahoo           levanchien_info
 * @email           chienlv@peacesoft.net
 * @mobile          0989092938
 * @description     Class xử lý các vấn đề liên quan đến seo
 */
class Seo {
    
    /**
     * create snippets 
     * <ul itemscope itemtype=”http://data-vocabulary.org/Breadcrumb”>

      <li><a itemprop=”url” href=”/” title=”Trang chủ”><span itemprop=”title”>Trang chủ</span></a></li>
      <li itemscope itemtype=”http://data-vocabulary.org/Breadcrumb”><a itemprop=”url” href=”/trang1″ title=”Trang 1″><span itemprop=”title”>Trang 1</span></a></li>
      <li itemscope itemtype=”http://data-vocabulary.org/Breadcrumb”><a itemprop=”url” href=”/trang2″ title=”Trang 2″><span itemprop=”title”>Trang 2</span></a></li>
      <li itemscope itemtype=”http://data-vocabulary.org/Breadcrumb”><a itemprop=”url” href=”/trang3″ title=”Trang 3″><span itemprop=”title”>Trang 3</span></a></li>
      </ul>
     * 
     * <div class="main f" itemscope itemtype="http://data-vocabulary.org/Recipe">
     * 
     * <div class="title-c cl nv" itemscope itemtype="http://data-vocabulary.org/Breadcrumb">
      <a itemprop="url" rel="nofollow" title="Trang chủ" href="/"><span itemprop="title">Trang chủ</span></a><span class="fl">&raquo;</span>
      <h2 itemscope itemtype="http://data-vocabulary.org/Breadcrumb"><a itemprop="url" title="Google SEO Việt" href="google-seo-việt"><span itemprop="title">Google SEO</span></a></h2>
      </div>
     */
    public function createSnippets($title, $description, $currUrl, $breadcrumb = array()) {
        $rateCount = (int) date('m') . date('d') . date('h') . date('i');
        $rateValue = rand(8, 10);

        $content = '<div itemscope itemtype="http://schema.org/Recipe" class="itemscope">';
        $content .= '<ul class="itemscope" itemscope itemtype="http://data-vocabulary.org/Breadcrumb">

            <li><a itemprop="url" href="'.SITE_URL.'" title="Trang chủ"><span itemprop="title">SaoBang.vn</span></a></li>';
        if ($breadcrumb) {
            foreach ($breadcrumb as $key => $value) {
                $content .= '<li itemscope itemtype="http://data-vocabulary.org/Breadcrumb"><a itemprop="url" href="' . $value['url'] . '" title="' . $value['name'] . '"><span itemprop="title">' . $value['name'] . '</span></a></li>';
            }
        }
        $content .= '</ul>';

        $content .= '<span itemprop="name">' . $title . '</span>            
        <div itemprop="aggregateRating" itemscope itemtype="http://schema.org/AggregateRating">
        <span itemprop="ratingValue">' . $rateValue . '</span>
        <span itemprop="bestRating">10</span>
        <span itemprop="ratingCount">' . $rateCount . '</span></div>
        <h2 itemprop="description">' . $description . '</h2></div>';
        return $content;
    }
    public function createSnippetsSearchPage($title, $description, $currUrl, $breadcrumb = array()) {
        $rateCount = (int) date('m') . date('d') . date('h');
        $rateValue = rand(8, 10);

        $content = '<div itemscope itemtype="http://schema.org/Recipe" class="itemscope">';
        $content .= '<ul class="itemscope" itemscope itemtype="http://data-vocabulary.org/Breadcrumb">

            <li><a itemprop="url" href="'.SITE_URL.'" title="Trang chủ"><span itemprop="title">'.SITE_URL.'</span></a></li>';
        if ($breadcrumb) {
            foreach ($breadcrumb as $key => $value) {
                $content .= '<li itemscope itemtype="http://data-vocabulary.org/Breadcrumb"><a itemprop="url" href="' . $value['url'] . '" title="' . $value['name'] . '"><span itemprop="title">' . $value['name'] . '</span></a></li>';
            }
        }
        $content .= '</ul>';


        $content .= '<span itemprop="name">' . $title . '</span>            
        <div itemprop="aggregateRating" itemscope itemtype="http://schema.org/AggregateRating">
        <span itemprop="ratingValue">' . $rateValue . '</span>
        <span itemprop="bestRating">10</span>
        <span itemprop="ratingCount">' . $rateCount . '</span></div>
        <h2 itemprop="description">' . $description . '</h2></div>';
        return $content;
    }

    /**
     *  snippet topic detail
     */
    public function createSnippetsDetail($title, $description, $currUrl, $breadcrumb = array(), $dataProviderKeyword) {
        $rateCount = (int) date('m') . date('d');
        $rateValue = rand(8, 10);

        $content = '<div itemscope itemtype="http://schema.org/Recipe" class="itemscope">';
        $content .= '<ul class="itemscope" itemscope itemtype="http://data-vocabulary.org/Breadcrumb">

            <li><a itemprop="url" href="'.SITE_URL.'" title="Trang chủ"><span itemprop="title">'.SITE_URL.'</span></a></li>';
        if ($breadcrumb) {
            foreach ($breadcrumb as $key => $value) {
                $content .= '<li itemscope itemtype="http://data-vocabulary.org/Breadcrumb"><a itemprop="url" href="' . $value['url'] . '" title="' . $value['name'] . '"><span itemprop="title">' . $value['name'] . '</span></a></li>';
            }
        }
        $content .= '</ul>';

        $content .= '<span itemprop="name">' . $title . '</span></div>';
        
        $content .= '<div class="itemscope" itemprop="aggregateRating" itemscope itemtype="http://schema.org/AggregateRating">
        <span itemprop="ratingValue">' . $rateValue . '</span>
        <span itemprop="bestRating">10</span>
        <span itemprop="ratingCount">' . $rateCount . '</span></div>';
        
        $i = 0;
        foreach ($dataProviderKeyword->getData() as $key => $data) {
            if ($i < 5) {
                $content .= '<div class="itemscope" itemscope itemtype="http://schema.org/Event">';
                $content .= '<a href="' . Yii::app()->createUrl('home/search', array('sid' => $data->id, 'catId' => $data->categoryId, 'childCat' => $data->childCatId, 'title' => ExtensionClass::utf8_to_ascii($data->name))) . '">' . ucfirst($data->name) . '</a>';
                $content .= '</div>';
            }
            $i++;
        }

        return $content;
    }
    
}

?>
